home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / c.lqr / SIEVE.C < prev    next >
Text File  |  1985-06-03  |  1KB  |  31 lines

  1.  
  2.  
  3. #define true 1
  4. #define false 0
  5. #define size 8190
  6. #define sizepl 8191
  7.  
  8. main() {
  9.         int i,prime,k,count,iter;
  10.         char flags[sizepl];
  11.         printf("10 iterations\n");
  12.         for(iter=1;iter<= 10;iter++){
  13.                 count=0;
  14.                 for(i = 0; i<=size;i++)
  15.                         flags[i]=true;
  16.                 for(i=0;i <= size; i++){
  17.                         if(flags[i]){
  18.                                 prime = i+i+3;
  19.                                 k=i+prime;
  20.                                         while(k<=size){
  21.                                                 flags[k] = false;
  22.                                                 k += prime;
  23.                                                 }
  24.                                         count = count+1;
  25.                                 }
  26.                         }
  27.                 }
  28.         printf("\n%d primes\n",count);
  29.         }
  30.  
  31.